package com.immunology.servlets;

import java.io.IOException;
import java.util.Enumeration;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.immunology.model.ComplaintType;
import com.immunology.model.MappingPages;
import com.immunology.model.Syndrome;
import com.immunology.service.ComplaintTypeService;
import com.immunology.service.SyndromeService;

public class EditComplaintTypeServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
    public EditComplaintTypeServlet() {
        super();
    }
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		getServletContext().getRequestDispatcher(
				MappingPages.SHOW_COMPLAINT_TYPE_JSP)
				.forward(request, response);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		String complaintTypeName = request.getParameter("complaintTypeName");
		Double complaintTypeMultuplier = Double.valueOf(request.getParameter("complaintTypeMultyplier"));
		@SuppressWarnings("unchecked")
		Enumeration<String> enumeration = request.getParameterNames();
		int complaintTypeId = Integer.parseInt(enumeration.nextElement());
		ComplaintTypeService complaintTypeService = ComplaintTypeService.getInstance();
		ComplaintType complaintType = complaintTypeService.getComplaintTypeById(complaintTypeId);
		complaintType.setName(complaintTypeName);
		complaintType.setMultyplier(complaintTypeMultuplier);
		complaintTypeService.update(complaintTypeId,complaintType);
		getServletContext()
				.getRequestDispatcher(MappingPages.SHOW_COMPLAINT_TYPE_JSP).forward(
						request, response);
	}

}
